class dropDownBtn extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      active: false
    }
    this.openClick = this.openClick.bind(this);
  }

  openClick() {
    this.setState({
      active: !this.state.active
    })
    let open = function(){
      if (this.state.active) {
        this.setState({
          active: false
        })
      } else {
        document.body.removeEventListener('click', open, false)
      }
    }.bind(this);
    if (!this.state.active) {
      document.body.addEventListener('click', open, false)
    } else {

    }
  }

  render() {
    return (
      <div className={this.state.active ? 'dropDownBtn active' : 'dropDownBtn'} onClick={this.openClick}>
        {this.props.children}
      </div>
    )
  }
}

module.exports = dropDownBtn;
